package com.zwb.aiwebsite.controller;

import com.zwb.aiwebsite.common.ResponseResult;
import com.zwb.aiwebsite.dto.ProductDTO;
import com.zwb.aiwebsite.entity.product.TbProduct;
import com.zwb.aiwebsite.entity.product.TbProductType;
import com.zwb.aiwebsite.service.TbProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * 产品中心控制器
 * @author 2825075112@qq.com
 */
@Controller
public class ProductController {

    @Resource
    private TbProductService tbProductService;

    @GetMapping("/admin/product/{page}")
    public String index(@PathVariable String page){
        return "/admin/product/" + page;
    }

    @PostMapping("/product/type")
    @ResponseBody
    public ResponseResult<Void> addProductType(@RequestBody TbProductType tbProductType){
        tbProductService.addProductType(tbProductType);
        return ResponseResult.ok();
    }

    @GetMapping("/product/type/all")
    @ResponseBody
    public ResponseResult<List<TbProductType>> getAllProductType(){
        List<TbProductType> all = tbProductService.getAllProductType();
        return ResponseResult.okOf(all);
    }

    @DeleteMapping("/product/type/{id}")
    @ResponseBody
    public ResponseResult<Void> delProductType(@PathVariable Integer id){
        tbProductService.delProductType(id);
        return ResponseResult.ok();
    }

    @GetMapping("/product/all")
    @ResponseBody
    public ResponseResult<List<TbProduct>> getAllProduct(){
        List<TbProduct> all = tbProductService.getAllProduct();
        return ResponseResult.okOf(all);
    }

    @DeleteMapping("/product/{id}")
    @ResponseBody
    public ResponseResult<Void> delProduct(@PathVariable Integer id){
        tbProductService.delProduct(id);
        return ResponseResult.ok();
    }

    @PostMapping("/product")
    @ResponseBody
    public ResponseResult<Void> addProduct(@RequestBody ProductDTO productDTO){
        tbProductService.addProduct(productDTO);
        return ResponseResult.ok();
    }

    @GetMapping("/product/info/all")
    @ResponseBody
    public ResponseResult<List<ProductDTO>> getAllProductInfo(){
        List<ProductDTO> all = tbProductService.getAllProductInfo();
        return ResponseResult.okOf(all);
    }

}
